/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package backing;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import model.CurrentUser;
import officeboost.domain.PersonService;
import officeboost.entity.User;


/**
 *
 * @author sorra
 */
@ManagedBean
public class InfoBacking extends AbstractBacking {
    @EJB
    private PersonService personService;
    @ManagedProperty(value="")
    String username;
    @ManagedProperty(value="")
    private String ID;
    @ManagedProperty(value="")
    private String gender;
    @ManagedProperty(value="")
    private String grade;
    @ManagedProperty(value="")
    private String phone;
    @ManagedProperty(value="")
    private String email;
    @ManagedProperty(value="")
    private String other;
    
    
    public InfoBacking() {
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    
    public String saveInfo(){
        //test
        String outcome="home";
        CurrentUser cu;  
        cu=(CurrentUser)getSessionMap().get("currentUser");
        User user;
        if((user=personService.find(cu.getUsername()))!=null)      
        {
            user.setEmail(this.email);
            user.setGender(this.gender);
            user.setIntroduction(this.other);
            user.setGrade(this.grade);
            user.setPhone(this.phone);
            personService.update(user);
            
        }
        
       return outcome;       

    }
    
    public String fillForm(){  
        
      //  this.setOther(()getSessionMap().get("equip"));
        CurrentUser cu;  
        cu=(CurrentUser)getSessionMap().get("currentUser");
        User user;
        if((user=personService.find(cu.getUsername()))!=null)
        {                      
             this.setID(user.getId());
             this.setUsername(user.getName());
             this.setEmail(user.getEmail());
             this.setGender(user.getGrade());
             this.setOther(user.getIntroduction());
             this.setEmail(user.getEmail());
             this.setPhone(user.getPhone());
        } 

        
        return "myinfos";
    }
}
